package com.tuniu.agents.impl.flight;

import com.tuniu.agents.agent.AgentManagerGroup;
import com.tuniu.agents.common.agent.Recommender;
import com.tuniu.agents.common.handler.FlightStreamResponseHandler;
import com.tuniu.agents.common.service.itinerary.ItineraryService;
import com.tuniu.agents.impl.flight.logger.FlightAgentService;
import com.tuniu.agents.message.MessageLogger;
import com.tuniu.agents.message.MessageSender;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightInformationQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightTimeQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightTransferQueryTool;
import com.tuniu.agents.tools.flights.domestic.roundtrip.RoundFlightInformationQueryTool;
import com.tuniu.agents.tools.flights.domestic.roundtrip.RoundFlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.international.oneway.IntlFlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.international.roundtrip.IntlRoundFlightLowPriceQueryTool;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * flight Agent Bean
 */
@Configuration
public class FlightAgentConfig {

    public static final String FLIGHT_TICKET_AGENT_ID = "FlightTicketAgent";

    public static final String FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_AGENT_ID = "FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS";

    public static final String FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_AGENT_ID = "FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS";

    public static final String FLIGHT_INTERNATIONAL_ONE_WAY_ANALYSIS_AGENT_ID = "FLIGHT_INTERNATIONAL_ONE_WAY_ANALYSIS";

    public static final String FLIGHT_INTERNATIONAL_ROUND_TRIP_ANALYSIS_AGENT_ID = "FLIGHT_INTERNATIONAL_ROUND_TRIP_ANALYSIS";


    public static final String FLIGHT_TICKET_PROMPT_TEMPLATE_ID = "flight-selection";

    public static final String FLIGHT_ANALYSIS_PROMPT_TEMPLATE_ID = "flight-recommend-header";

    public static final String FLIGHT_ONE_WAY_RECOMMEND_PROMPT_TEMPLATE_ID = "flight-one-way-recommend";

    public static final String FLIGHT_ROUND_TRIP_RECOMMEND_PROMPT_TEMPLATE_ID = "flight-round-trip-recommend";


    @Autowired
    ItineraryService itineraryService;

    @Bean(FLIGHT_TICKET_AGENT_ID)
    @SneakyThrows
    public FlightTicketAgent flightTicketAgent(AgentManagerGroup agentManagerGroup, MessageSender messageSender) {
        MessageLogger logger = new MessageLogger(FlightAgentService.BEAN_NAME);
        return new FlightTicketAgent(agentManagerGroup, FLIGHT_TICKET_AGENT_ID, messageSender, FLIGHT_TICKET_PROMPT_TEMPLATE_ID, logger,
                FlightLowPriceQueryTool.TOOLNAME, FlightTransferQueryTool.TOOLNAME,  FlightTimeQueryTool.TOOLNAME,
                RoundFlightLowPriceQueryTool.TOOLNAME, FlightInformationQueryTool.TOOLNAME, RoundFlightInformationQueryTool.TOOLNAME);
    }

    @Bean(FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_AGENT_ID)
    @SneakyThrows
    public Recommender domesticOneWayAnalysisAgent(AgentManagerGroup agentManagerGroup) {
        //return new AnalysisAgent(agentManagerGroup, FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_AGENT_ID, FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_PROMPT_TEMPLATE_ID);
        return new FlightRecommender(agentManagerGroup, FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_AGENT_ID,FLIGHT_ONE_WAY_RECOMMEND_PROMPT_TEMPLATE_ID,
                new FlightStreamResponseHandler(FlightLowPriceQueryTool.TOOLNAME, FLIGHT_DOMESTIC_ONE_WAY_ANALYSIS_AGENT_ID, agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(), agentManagerGroup.getMessageRender(), itineraryService));

    }

    @Bean(FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_AGENT_ID)
    @SneakyThrows
    public Recommender domesticRoundTripAnalysisAgent(AgentManagerGroup agentManagerGroup) {
        //return new AnalysisAgent(agentManagerGroup, FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_AGENT_ID, FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_PROMPT_TEMPLATE_ID);
        return new FlightRecommender(agentManagerGroup, FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_AGENT_ID,FLIGHT_ROUND_TRIP_RECOMMEND_PROMPT_TEMPLATE_ID,
                new FlightStreamResponseHandler(RoundFlightLowPriceQueryTool.TOOLNAME,FLIGHT_DOMESTIC_ROUND_TRIP_ANALYSIS_AGENT_ID,agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(), agentManagerGroup.getMessageRender(), itineraryService));
    }

    @Bean(FLIGHT_INTERNATIONAL_ONE_WAY_ANALYSIS_AGENT_ID)
    @SneakyThrows
    public Recommender internationalOneWayAnalysisAgent(AgentManagerGroup agentManagerGroup) {
        return new FlightRecommender(agentManagerGroup, FLIGHT_INTERNATIONAL_ONE_WAY_ANALYSIS_AGENT_ID, FLIGHT_ONE_WAY_RECOMMEND_PROMPT_TEMPLATE_ID,
                new FlightStreamResponseHandler(IntlFlightLowPriceQueryTool.TOOLNAME, FLIGHT_INTERNATIONAL_ONE_WAY_ANALYSIS_AGENT_ID,agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(), agentManagerGroup.getMessageRender(), itineraryService));
    }

    @Bean(FLIGHT_INTERNATIONAL_ROUND_TRIP_ANALYSIS_AGENT_ID)
    @SneakyThrows
    public Recommender internationalRoundTripAnalysisAgent(AgentManagerGroup agentManagerGroup) {
        return new FlightRecommender(agentManagerGroup, FLIGHT_INTERNATIONAL_ROUND_TRIP_ANALYSIS_AGENT_ID, FLIGHT_ROUND_TRIP_RECOMMEND_PROMPT_TEMPLATE_ID,
                new FlightStreamResponseHandler(IntlRoundFlightLowPriceQueryTool.TOOLNAME, FLIGHT_INTERNATIONAL_ROUND_TRIP_ANALYSIS_AGENT_ID, agentManagerGroup.getChatEnvironmentMemory(), agentManagerGroup.getMemoryManager(), agentManagerGroup.getMessageRender(), itineraryService));
    }
}
